package net.qiqb.dao.mybatis.plus.event;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.qiqb.core.domain.event.types.DomainEventStatus;

import java.util.List;

public class DomainEventDaoImpl extends ServiceImpl<DomainEventPOMapper, DomainEventPO> implements DomainEventDao {


    @Override
    public boolean save(List<DomainEventPO> domainEventPOS) {
        return super.saveBatch(domainEventPOS);
    }

    @Override
    public List<DomainEventPO> listReady() {
        QueryWrapper<DomainEventPO> queryWrapper = new QueryWrapper<>();
        // 查等待下发的领域事件
        queryWrapper.lambda().eq(DomainEventPO::getStatus, DomainEventStatus.ready);
        return super.list(queryWrapper);
    }

    @Override
    public boolean updateStatusById(String id, DomainEventStatus status) {
        UpdateWrapper<DomainEventPO> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(DomainEventPO::getId, id).set(DomainEventPO::getStatus, status);
        return super.update(updateWrapper);
    }
}
